#include "precom.h"
#include "SimpleShader.h"

SimpleShader::SimpleShader()
{
	m_lightNum = 5;
}

SimpleShader::~SimpleShader()
{
}

bool SimpleShader::CgShaderInit(HWND a_hWnd, CGcontext a_cg_context,
		CGprofile a_cg_vertProfile, CGprofile a_cg_fragProfile)
{
	cg_vertProg = cgCreateProgramFromFile(a_cg_context, CG_SOURCE, "Res/simple.cg",
					a_cg_vertProfile, "vertshader", 0);
	if( cg_vertProg == NULL ) {
		CGerror err = cgGetError();
		MessageBoxA(a_hWnd, cgGetErrorString(err), "Error VertCG", MB_OK);
		return false;
	}
	cg_fragProg = cgCreateProgramFromFile(a_cg_context, CG_SOURCE, "Res/simple.cg",
					a_cg_fragProfile, "fragshader", 0);
	if( cg_fragProg == NULL ) {
		CGerror err = cgGetError();
		MessageBoxA(a_hWnd, cgGetErrorString(err), "Error FragCG", MB_OK);
		return false;
	}
	
	cgGLLoadProgram(cg_vertProg);
	cgGLLoadProgram(cg_fragProg);
	
	cg_lightPos[0] = cgGetNamedParameter(cg_vertProg, "LightPos[0]");
	cg_lightPos[1] = cgGetNamedParameter(cg_vertProg, "LightPos[1]");
	cg_lightPos[2] = cgGetNamedParameter(cg_vertProg, "LightPos[2]");
	cg_lightPos[3] = cgGetNamedParameter(cg_vertProg, "LightPos[3]");
	cg_lightPos[4] = cgGetNamedParameter(cg_vertProg, "LightPos[4]");
	cg_eyePos = cgGetNamedParameter(cg_vertProg, "EyePos");
	cg_modelViewMatrix = cgGetNamedParameter(cg_vertProg, "ModelView");
	cg_modelViewProjMatrix = cgGetNamedParameter(cg_vertProg, "ModelViewProj");
	return true;
}

std::vector<boost::function<void(float)>> SimpleShader::SignUpForFloatInfo()
{
	std::vector<boost::function<void(float)>> ret;
	ret.resize(ShaderExternalFloatDataNum, NULL);
	return ret;
}

std::vector<boost::function<void(const fmath::vector3&)>> SimpleShader::SignUpForVecInfo()
{
	std::vector<boost::function<void(const fmath::vector3&)>> ret;
	ret.resize(ShaderExternalVecDataNum, NULL);
	ret[CgEnum_EyePos] = boost::bind(&SimpleShader::SetEyePos, &(*this), _1);
	return ret;
}
